/*
 * Copyright (c) 2011. This file is public under GPLv3 license.
 * For more information about license please refer to http://www.gnu.org/licenses/gpl.html
 */

package com.freetools.watchdog.model;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

/**
 * Describes one log record
 * Date: Jun 23, 2010
 *
 * @author Michael Morozov
 */
public class Record implements IRecord
{
    private List<IPiece> pieces = new ArrayList<IPiece>();
    private Map<IColumn, Object> values = new HashMap<IColumn, Object>();
    private Pattern pattern;
    private long id;

    public Record()
    {
    }

    public Record(long id)
    {
        this.id = id;
    }

    public long getId()
    {
        return id;
    }

    public List<IPiece> getPieces()
    {
        return pieces;
    }

    public String getText() throws IOException
    {
        StringBuilder builder = new StringBuilder();
        for (IPiece piece : getPieces())
        {
            builder.append(piece.getCachedValue());
        }
        return builder.toString();
    }

    public Object getValue(IColumn column)
    {
        return values.get(column);
    }

    public void setValue(Object value, IColumn column)
    {
        values.put(column, value);
    }
}
